<?php
	session_start();
	require_once("../config.php");
	include_once("../database/DataBase.php");
	
	$search_type = $_POST["search_type"];
	$keyword = $_POST["keyword"];
	
	$database = New DataBase();
	$database->open_connection();
	$result = $database->getProductByCodeOrName($search_type, $keyword);
	
	if($result != null){	
		echo "<table>";
		echo "<tr><td>Code</td><td>Name</td><td>Description</td><td>Category</td><td>Store in</td><td>Expire</td><td>Quantity</td><td>Price</td><td>Status</td><td>Action</td></tr>";
			while ($row = mysql_fetch_assoc($result)) {
				echo "<tr>";
				echo "<td>".$row["product_code"]."</td>";
				echo "<td>".$row["name"]."</td>";
				echo "<td>".$row["description"]."</td>";
				echo "<td>".$row["category"]."</td>";
				echo "<td>".$row["store_in_date"]."</td>";
				echo "<td>".$row["expire_date"]."</td>";
				echo "<td>".$row["quantity"]."</td>";
				echo "<td>".$row["price"]."</td>";
				echo "<td>".$row["status"]."</td>";
				echo "<td><a href='product_edit.php?code=".$row["pid"]."'>Edit</a> / <a href='product_delete.php?code=".$row["product_code"]."'>Delete</a></td>";
				echo "</tr>";
			}
		echo "</table>";
	}
	else{
		echo "<p>No such user in system.</p>";
	}

	
	$database->close_connection();
?>